﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using University.Workshop.DataAccess;
using System.Threading;
using System.Globalization;
using University.Workshop.DataAccess.LanguagePack.ClientLanguagePack;

namespace University.Workshop.ClientApp
{
    /// <summary>
    /// Interaction logic for Galery.xaml
    /// </summary>
    public partial class Galery : Window
    {
        private string LanguageSelected;

        private string GalleryLabelLevel1Yes1;
        private string GalleryLabelLevel1Yes2;
        private string GalleryLabelLevel1Yes3;


        User user;
        public Galery()
        {
            InitializeComponent();
        }
        public Galery(User userReceived)
        {
            InitializeComponent();
            user = userReceived;

            labelUserName.Content = user.Name;
            labelUserChips.Content = user.Chips;
            radioButtonLevel1.Visibility = Visibility.Hidden;
            radioButtonLevel2.Visibility = Visibility.Hidden;
            radioButtonLevel3.Visibility = Visibility.Hidden;
            
            
           

            for (int i = 0; i < user.Decks.Count ; i++)
            {
                if (user.Decks[i] != 0)
                {
                    if (user.Decks[i] == 1)
                    {
                        labelLevel1.Content = this.GalleryLabelLevel1Yes1;
                        buttonSale1.IsEnabled = true;
                        radioButtonLevel1.Visibility = Visibility.Visible;
                        buttonBuy1.IsEnabled = false;
                        if (user.DeckUserPresent == 1) radioButtonLevel1.IsChecked = true;
                    }
                    if (user.Decks[i] == 2)
                    {
                        labelLevel2.Content = this.GalleryLabelLevel1Yes2;
                        buttonSale2.IsEnabled = true;
                        radioButtonLevel2.Visibility = Visibility.Visible;
                        buttonBuy2.IsEnabled = false;
                        if (user.DeckUserPresent == 2) radioButtonLevel2.IsChecked = true;
                    }
                    if (user.Decks[i] == 3)
                    {
                        labelLevel3.Content = this.GalleryLabelLevel1Yes3;
                        buttonSale3.IsEnabled = true;
                        radioButtonLevel3.Visibility = Visibility.Visible;
                        buttonBuy3.IsEnabled = false;
                        if (user.DeckUserPresent == 3)  radioButtonLevel3.IsChecked = true;
                    }
                 }
                    
            }
            
        }

        public Galery(User userReceived, string languageSelected)
        {
            InitializeComponent();
            user = userReceived;

            this.LanguageSelected = languageSelected;
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.LanguageSelected);
            ApplyLanguage();

            labelUserName.Content = user.Name;
            labelUserChips.Content = user.Chips;
            radioButtonLevel1.Visibility = Visibility.Hidden;
            radioButtonLevel2.Visibility = Visibility.Hidden;
            radioButtonLevel3.Visibility = Visibility.Hidden;




            for (int i = 0; i < user.Decks.Count; i++)
            {
                if (user.Decks[i] != 0)
                {
                    if (user.Decks[i] == 1)
                    {
                        labelLevel1.Content = this.GalleryLabelLevel1Yes1;
                        buttonSale1.IsEnabled = true;
                        radioButtonLevel1.Visibility = Visibility.Visible;
                        buttonBuy1.IsEnabled = false;
                        if (user.DeckUserPresent == 1) radioButtonLevel1.IsChecked = true;
                    }
                    if (user.Decks[i] == 2)
                    {
                        labelLevel2.Content = this.GalleryLabelLevel1Yes2;
                        buttonSale2.IsEnabled = true;
                        radioButtonLevel2.Visibility = Visibility.Visible;
                        buttonBuy2.IsEnabled = false;
                        if (user.DeckUserPresent == 2) radioButtonLevel2.IsChecked = true;
                    }
                    if (user.Decks[i] == 3)
                    {
                        labelLevel3.Content = this.GalleryLabelLevel1Yes3;
                        buttonSale3.IsEnabled = true;
                        radioButtonLevel3.Visibility = Visibility.Visible;
                        buttonBuy3.IsEnabled = false;
                        if (user.DeckUserPresent == 3) radioButtonLevel3.IsChecked = true;
                    }
                }

            }

        }

        private void ApplyLanguage()
        {
            this.GalleryLabelLevel1Yes1 = ClientLanguagePack.GalleryLabelLevel1Yes;
            this.GalleryLabelLevel1Yes2 = ClientLanguagePack.GalleryLabelLevel2Yes;
            this.GalleryLabelLevel1Yes3 = ClientLanguagePack.GalleryLabelLevel3Yes;

            this.label1.Content = ClientLanguagePack.GalleryTitle;
            this.label2.Content = ClientLanguagePack.GalleryLabelUser;
            this.label3.Content = ClientLanguagePack.GalleryLabelChips;
            this.label10.Content = ClientLanguagePack.GalleryLabelSelectADeckForGame;
            this.radioButtonLevel1.Content = ClientLanguagePack.GalleryLabelLevel1;
            this.radioButtonLevel2.Content = ClientLanguagePack.GalleryLabelLevel2;
            this.radioButtonLevel3.Content = ClientLanguagePack.GalleryLabelLevel3;
            this.labelLevel1.Content = ClientLanguagePack.GalleryLabelLevel1No;
            this.labelLevel2.Content = ClientLanguagePack.GalleryLabelLevel2No;
            this.labelLevel3.Content = ClientLanguagePack.GalleryLabelLevel3No;
            this.label4.Content = ClientLanguagePack.GalleryChips250;
            this.label8.Content = ClientLanguagePack.GalleryChips500;
            this.label9.Content = ClientLanguagePack.GalleryChips1000;
            this.buttonSale1.Content = ClientLanguagePack.GalleryButtonSale1;
            this.buttonSale2.Content = ClientLanguagePack.GalleryButtonSale2;
            this.buttonSale3.Content = ClientLanguagePack.GalleryButtonSale3;
            this.label5.Content = ClientLanguagePack.GalleryLabelLevel1;
            this.label6.Content = ClientLanguagePack.GalleryLabelLevel2;
            this.label7.Content = ClientLanguagePack.GalleryLabelLevel3;

            this.groupBox3.Header = ClientLanguagePack.GalleryGroupAvailableDecks;
            this.groupBox2.Header = ClientLanguagePack.GalleryGroupDecks;
            this.groupBox1.Header = ClientLanguagePack.GalleryGroupUsersForSale;

            this.buttonBuy1.Content = ClientLanguagePack.GalleryButtonBuy500;
            this.buttonBuy2.Content = ClientLanguagePack.GalleryButtonBuy1000;
            this.buttonBuy3.Content = ClientLanguagePack.GalleryButtonBuy2000;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //GaleryConfirm galery = new GaleryConfirm(user, "buy", 500, 1, "Images/ImagesDecks/de1.png");
            GaleryConfirm galery = new GaleryConfirm(user, "buy", 500, 1, "Images/ImagesDecks/de1.png", this.LanguageSelected);
            galery.ShowDialog();

            labelUserName.Content = user.Name;
            labelUserChips.Content = user.Chips;
            radioButtonLevel1.Visibility = Visibility.Hidden;
            radioButtonLevel2.Visibility = Visibility.Hidden;
            radioButtonLevel3.Visibility = Visibility.Hidden;
            for (int i = 0; i < user.Decks.Count; i++)
            {
                if (user.Decks[i] != 0)
                {
                    if (user.Decks[i] == 1)
                    {
                        labelLevel1.Content = this.GalleryLabelLevel1Yes1;
                        buttonSale1.IsEnabled = true;
                        radioButtonLevel1.Visibility = Visibility.Visible;
                        buttonBuy1.IsEnabled = false;

                    }
                    if (user.Decks[i] == 2)
                    {
                        labelLevel2.Content = this.GalleryLabelLevel1Yes2;
                        buttonSale2.IsEnabled = true;
                        radioButtonLevel2.Visibility = Visibility.Visible;
                        buttonBuy2.IsEnabled = false;

                    }
                    if (user.Decks[i] == 3)
                    {
                        labelLevel3.Content = this.GalleryLabelLevel1Yes3;
                        buttonSale3.IsEnabled = true;
                        radioButtonLevel3.Visibility = Visibility.Visible;
                        buttonBuy3.IsEnabled = false;

                    }
                }

            }
            
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void buttonBuy2_Click(object sender, RoutedEventArgs e)
        {
            //GaleryConfirm galery = new GaleryConfirm(user, "buy", 1000, 2, "Images/ImagesDecks/de2.png");
            GaleryConfirm galery = new GaleryConfirm(user, "buy", 1000, 2, "Images/ImagesDecks/de2.png", this.LanguageSelected);
            galery.ShowDialog();

            labelUserName.Content = user.Name;
            labelUserChips.Content = user.Chips; 
            radioButtonLevel1.Visibility = Visibility.Hidden;
            radioButtonLevel2.Visibility = Visibility.Hidden;
            radioButtonLevel3.Visibility = Visibility.Hidden;
            for (int i = 0; i < user.Decks.Count; i++)
            {
                if (user.Decks[i] != 0)
                {
                    if (user.Decks[i] == 1)
                    {
                        labelLevel1.Content = this.GalleryLabelLevel1Yes1;
                        buttonSale1.IsEnabled = true;
                        radioButtonLevel1.Visibility = Visibility.Visible;
                        buttonBuy1.IsEnabled = false;

                    }
                    if (user.Decks[i] == 2)
                    {
                        labelLevel2.Content = this.GalleryLabelLevel1Yes2;
                        buttonSale2.IsEnabled = true;
                        radioButtonLevel2.Visibility = Visibility.Visible;
                        buttonBuy2.IsEnabled = false;

                    }
                    if (user.Decks[i] == 3)
                    {
                        labelLevel3.Content = this.GalleryLabelLevel1Yes3;
                        buttonSale3.IsEnabled = true;
                        radioButtonLevel3.Visibility = Visibility.Visible;
                        buttonBuy3.IsEnabled = false;

                    }
                }

            }
        }

        private void button1_Click_1(object sender, RoutedEventArgs e)
        {
            //GaleryConfirm galery = new GaleryConfirm(user, "buy", 2000, 3, "Images/ImagesDecks/de3.jpg");
            GaleryConfirm galery = new GaleryConfirm(user, "buy", 2000, 3, "Images/ImagesDecks/de3.jpg", this.LanguageSelected);
            galery.ShowDialog();

            labelUserName.Content = user.Name;
            labelUserChips.Content = user.Chips;
            radioButtonLevel1.Visibility = Visibility.Hidden;
            radioButtonLevel2.Visibility = Visibility.Hidden;
            radioButtonLevel3.Visibility = Visibility.Hidden;
            for (int i = 0; i < user.Decks.Count; i++)
            {
                if (user.Decks[i] != 0)
                {
                    if (user.Decks[i] == 1)
                    {
                        labelLevel1.Content = this.GalleryLabelLevel1Yes1;
                        buttonSale1.IsEnabled = true;
                        radioButtonLevel1.Visibility = Visibility.Visible;
                        buttonBuy1.IsEnabled = false;

                    }
                    if (user.Decks[i] == 2)
                    {
                        labelLevel2.Content = this.GalleryLabelLevel1Yes2;
                        buttonSale2.IsEnabled = true;
                        radioButtonLevel2.Visibility = Visibility.Visible;
                        buttonBuy2.IsEnabled = false;

                    }
                    if (user.Decks[i] == 3)
                    {
                        labelLevel3.Content = this.GalleryLabelLevel1Yes3;
                        buttonSale3.IsEnabled = true;
                        radioButtonLevel3.Visibility = Visibility.Visible;
                        buttonBuy3.IsEnabled = false;

                    }
                }

            }
        }

        private void buttonSale1_Click(object sender, RoutedEventArgs e)
        {
            //GaleryConfirm galery = new GaleryConfirm(user, "sale", 250, 1, "Images/ImagesDecks/de1.png");
            GaleryConfirm galery = new GaleryConfirm(user, "sale", 250, 1, "Images/ImagesDecks/de1.png", this.LanguageSelected);
            galery.ShowDialog();

            labelUserName.Content = user.Name;
            labelUserChips.Content = user.Chips;

            buttonSale1.IsEnabled = false;
            buttonSale2.IsEnabled = false;
            buttonSale3.IsEnabled = false;
            buttonBuy1.IsEnabled = true;
            buttonBuy2.IsEnabled = true;
            buttonBuy3.IsEnabled = true;
            radioButtonLevel1.Visibility = Visibility.Hidden;
            radioButtonLevel2.Visibility = Visibility.Hidden;
            radioButtonLevel3.Visibility = Visibility.Hidden;
            for (int i = 0; i < user.Decks.Count; i++)
            {
                if (user.Decks[i] != 0)
                {
                    if (user.Decks[i] == 1)
                    {
                        labelLevel1.Content = this.GalleryLabelLevel1Yes1;
                        buttonSale1.IsEnabled = true;
                        radioButtonLevel1.Visibility = Visibility.Visible;
                        buttonBuy1.IsEnabled = false;

                    }
                    if (user.Decks[i] == 2)
                    {
                        labelLevel2.Content = this.GalleryLabelLevel1Yes2;
                        buttonSale2.IsEnabled = true;
                        radioButtonLevel2.Visibility = Visibility.Visible;
                        buttonBuy2.IsEnabled = false;

                    }
                    if (user.Decks[i] == 3)
                    {
                        labelLevel3.Content = this.GalleryLabelLevel1Yes3;
                        buttonSale3.IsEnabled = true;
                        radioButtonLevel3.Visibility = Visibility.Visible;
                        buttonBuy3.IsEnabled = false;

                    }
                }

            }
        }

        private void buttonSale2_Click(object sender, RoutedEventArgs e)
        {
            //GaleryConfirm galery = new GaleryConfirm(user, "sale", 500, 2, "Images/ImagesDecks/de2.jpg");
            GaleryConfirm galery = new GaleryConfirm(user, "sale", 500, 2, "Images/ImagesDecks/de2.jpg", this.LanguageSelected);
            galery.ShowDialog();

            labelUserName.Content = user.Name;
            labelUserChips.Content = user.Chips;

            buttonSale1.IsEnabled = false;
            buttonSale2.IsEnabled = false;
            buttonSale3.IsEnabled = false;
            buttonBuy1.IsEnabled = true;
            buttonBuy2.IsEnabled = true;
            buttonBuy3.IsEnabled = true;
            radioButtonLevel1.Visibility = Visibility.Hidden;
            radioButtonLevel2.Visibility = Visibility.Hidden;
            radioButtonLevel3.Visibility = Visibility.Hidden;
            for (int i = 0; i < user.Decks.Count; i++)
            {
                if (user.Decks[i] != 0)
                {
                    if (user.Decks[i] == 1)
                    {
                        labelLevel1.Content = this.GalleryLabelLevel1Yes1;
                        buttonSale1.IsEnabled = true;
                        radioButtonLevel1.Visibility = Visibility.Visible;
                        buttonBuy1.IsEnabled = false;

                    }
                    if (user.Decks[i] == 2)
                    {
                        labelLevel2.Content = this.GalleryLabelLevel1Yes2;
                        buttonSale2.IsEnabled = true;
                        radioButtonLevel2.Visibility = Visibility.Visible;
                        buttonBuy2.IsEnabled = false;

                    }
                    if (user.Decks[i] == 3)
                    {
                        labelLevel3.Content = this.GalleryLabelLevel1Yes3;
                        buttonSale3.IsEnabled = true;
                        radioButtonLevel3.Visibility = Visibility.Visible;
                        buttonBuy3.IsEnabled = false;

                    }
                }

            }
        }

        private void buttonSale3_Click(object sender, RoutedEventArgs e)
        {

            //GaleryConfirm galery = new GaleryConfirm(user, "sale", 1000, 3, "Images/ImagesDecks/de3.jpg");
            GaleryConfirm galery = new GaleryConfirm(user, "sale", 1000, 3, "Images/ImagesDecks/de3.jpg", this.LanguageSelected);
            galery.ShowDialog();

            labelUserName.Content = user.Name;
            labelUserChips.Content = user.Chips;

            buttonSale1.IsEnabled = false;
            buttonSale2.IsEnabled = false;
            buttonSale3.IsEnabled = false;
            buttonBuy1.IsEnabled = true; 
            buttonBuy2.IsEnabled = true;
            buttonBuy3.IsEnabled = true; 
            radioButtonLevel1.Visibility = Visibility.Hidden;
            radioButtonLevel2.Visibility = Visibility.Hidden;
            radioButtonLevel3.Visibility = Visibility.Hidden;
            for (int i = 0; i < user.Decks.Count; i++)
            {
                if (user.Decks[i] != 0)
                {
                    if (user.Decks[i] == 1)
                    {
                        labelLevel1.Content = this.GalleryLabelLevel1Yes1;
                        buttonSale1.IsEnabled = true;
                        radioButtonLevel1.Visibility = Visibility.Visible;
                        buttonBuy1.IsEnabled = false;

                    }
                    if (user.Decks[i] == 2)
                    {
                        labelLevel2.Content = this.GalleryLabelLevel1Yes2;
                        buttonSale2.IsEnabled = true;
                        radioButtonLevel2.Visibility = Visibility.Visible;
                        buttonBuy2.IsEnabled = false;

                    }
                    if (user.Decks[i] == 3)
                    {
                        labelLevel3.Content = this.GalleryLabelLevel1Yes3;
                        buttonSale3.IsEnabled = true;
                        radioButtonLevel3.Visibility = Visibility.Visible;
                        buttonBuy3.IsEnabled = false;

                    }
                }

            }
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            if (radioButtonLevel1.Visibility == Visibility.Visible)
                if (radioButtonLevel1.IsChecked == true)
                    user.DeckUserPresent = 1;
            if (radioButtonLevel2.Visibility == Visibility.Visible)
                if (radioButtonLevel2.IsChecked == true)
                    user.DeckUserPresent = 2;
            if (radioButtonLevel3.Visibility == Visibility.Visible)
                if (radioButtonLevel3.IsChecked == true)
                    user.DeckUserPresent = 3;
        }

        
    }
}
